<template>
  <!-- 受众看板 -->
  <div class="app-container">
    <div class="theme-bg">
      <div class="audience-title">
        参考对象: {{ currentItem[0] && currentItem[0].name || '' }}
        <el-button type="text" style="color: #fff; float: right;" @click="$router.go(-1)">
          <svg-icon icon-class="back"></svg-icon>
          返回
        </el-button>
      </div>
      <div class="top-board">
        <div class="left-img">
          <RadarChart :chartData="chartData"></RadarChart>
        </div>
        <div class="right-board">
          <div class="select-wrapper">
            <el-checkbox-group v-model="checkedValue">
              <el-checkbox :label="item" v-for="item in otherItems" :key="item.id">{{ item.name }}</el-checkbox>
            </el-checkbox-group>
          </div>
          <div class="button-wrapper">
            <el-button @click="onReset">重置</el-button>
            <el-button type="primary" @click="onConfirm">确定</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import RadarChart from "../../dashboard/RadarChart.vue"
import { getAudienceAllList } from "@/api/library/audience"
export default {
  name: "Engine",
  components: { RadarChart },
  data () {
    return {
      chartData: [],
      currentItem: [],
      otherItems: [],
      query: {},
      checkedValue: []
    };
  },
  created () {
    this.query = this.$route.query;
    this.getAudienceCurrent()
  },
  methods: {
    format (percentage) {
      return `${percentage}`;
    },
    onConfirm () {
      this.chartData = [...this.currentItem, ...this.checkedValue]
    },
    onReset() {
      this.checkedValue = []
      this.chartData = this.currentItem;
    },
    getAudienceCurrent () {
      getAudienceAllList().then(res => {
        const chartData = res.data || []
        this.currentItem = chartData.filter(item => item.id == this.query.id && Object.keys(item.audienceFactorScore).length) || []
        this.otherItems = chartData.filter(item => item.id != this.query.id && Object.keys(item.audienceFactorScore).length) || []
        this.chartData = this.currentItem;
      })
    }
  }
};
</script>
<style lang="scss" scoped>
.app-container {
  padding: 32px;

  .mask {
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    text-align: center;
  }
}

.theme-bg {
  color: #fff;
  padding: 20px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
}

.audience-title {
  color: #FFF;
  font-size: 24px;
  font-weight: bold;
  line-height: 34px;
  margin-bottom: 14px;
}

.top-board {
  display: flex;

  .left-img {
    flex: 1;
    min-width: 800px;
    display: flex;
    justify-content: center;
    margin-right: 20px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 8px;

  }

  .right-board {
    flex: 400px 0 0;
    height: 836px;
    display: flex;
    flex-direction: column;
    .select-wrapper {
      background: rgba(255, 255, 255, 0.06);
      border-radius: 12px;
      flex: 1;
      padding: 24px;
      overflow-x: hidden;
      overflow-y: auto;
      ::v-deep .el-checkbox {
        display: block;
        margin-bottom: 32px;
        .el-checkbox__label {
          color: #fff;
          font-size: 16px;
          font-weight: normal;
        }
      }
    }
    .button-wrapper {
      background: rgba(255, 255, 255, 0.06);
      padding: 20px;
      border-radius: 12px;
      margin-top: 20px;
      text-align: right;
      .el-button {
        width: 102px;
        height: 40px;
        &.el-button--default {
          background: #4D4E5F;
          border: 1px solid #4D4E5F;
          color: #fff;
        }
      }
    }
  }
}
</style>